<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="renderer" content="webkit|ie-comp|ie-stand">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <title>公司列表</title>
  <script src="../../../static/kaige/js/szload.js"></script>
  <style>
    .kaige-body-form .layui-form-item .layui-form-label {
      width: 120px;
    }

    .logoimg {
      width: 60px;
      height: 60px;
    }

    .layui-table-tree td .layui-table-cell {
      height: 70px;
      line-height: 60px
    }

    .layui-table-tree td .layui-table-cell img {
      max-width: 48px;
      max-height: 48px;
    }
  </style>
</head>

<body>
  <div class="kaige-body layui-form kaige-btn-radius" lay-filter="company-index">
    <table class="layui-table" id="companyTable" lay-filter="companyTable" lay-size="sm"></table>
  </div>
  <script type="text/html" id="TPL-treeTable-header">
    <div class="layui-btn-group">
      <button type="button" class="layui-btn layui-bg-blue layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i> 添加</button>
      <button type="button" class="layui-btn layui-bg-blue layui-btn-sm" lay-event="reload"><i class="layui-icon layui-icon-refresh"></i> 刷新</button>
      <button type="button" class="layui-btn layui-bg-blue layui-btn-sm" lay-event="open-all"><i class="layui-icon layui-icon-down"></i> 全展开</button>
      <button type="button" class="layui-btn layui-bg-blue layui-btn-sm" lay-event="close-all"><i class="layui-icon layui-icon-right"></i> 全关闭</button>
    </div>
  </script>
  <script type="text/html" id="TPL-treeTable-tdbar">
    <div class="layui-btn-group">
      <a class="layui-btn layui-bg-blue layui-btn-sm" lay-event="look"><i class="layui-icon layui-icon-eye"></i></a>
      <a class="layui-btn layui-bg-blue layui-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></a>
      <a class="layui-btn layui-bg-red layui-btn-sm"  lay-event="del"><i class="layui-icon layui-icon-delete"></i></a>
    </div>
  </script>
  <script>
    load_init_js(function () {
      layui.config({
        base: szoapcpath + '/static/kaige/layuiextend/'
      }).use(['kaige', 'tableSelect'], function () {
        var treeTable = layui.treeTable, $ = layui.$, kaige = layui.kaige, tableSelect = layui.tableSelect, form = layui.form,layer = layui.layer;
        //查看图片
        window.viewImage = function (imgUrl) { kaige.viewimage({ maxwidth: 600, maxheight: 600, url: imgUrl }); }
        // 渲染表格
        var companyre = treeTable.render({
          elem: "#companyTable",
          id: "IDcompanyTable",
          url: "/hrm.company/index",
          toolbar: '#TPL-treeTable-header',
          height: 'full-35',
          cols: [[
            { field: 'id', title: 'ID', width: 50 },
            {
              field: 'logo', title: 'LOGO', width: 90, templet: function (d) {
                return '<img src="' + d.logo + '" onclick="viewImage(\'' + d.logo + '\')" class="logoimg" alt=""/>';
              }
            },
            { field: 'name', title: '简称', width: 150 },
            { field: 'fullname', title: '全称', width: 260 },
            {
              field: 'pobj', title: '上级单位', width: 160, templet: function (item) {
                if (item.pobj && item.pobj.name) {
                  return item.pobj.name;
                }
                return '无'
              }
            },
            { field: 'headman', title: '负责人', width: 100 },
            { field: 'city', title: '所在城市', width: 120 },
            { field: 'sort', title: '排序', width: 60, edit: 'text' },
            { field: 'status', title: '状态', width: 100, align: 'center', templet: "#status_td" },
            { fixed: "right", title: "操作", width: 200, align: "center", toolbar: "#TPL-treeTable-tdbar" },
          ]],
          page: false,
          tree: {
            view: { expandAllDefault: true, showIcon: false }
          }
        });

        // 表头工具栏工具事件
        treeTable.on("toolbar(companyTable)", function (obj) {
          // 获取选中行
          switch (obj.event) {
            case "add":
              btn_add();
              break;
            case "reload":
              treeTable.reloadData('IDcompanyTable');
              break;
            case "open-all":
              treeTable.expandAll('IDcompanyTable', true); // 展开全部节点
              break;
            case "close-all":
              treeTable.expandAll('IDcompanyTable', false); // 关闭全部节点
              break;
          }
        });

        // 单元格工具事件--此处是 filter  不是 id
        treeTable.on('tool(companyTable)', function (obj) {
          switch (obj.event) {
            case "look":
              btn_look(obj.data);
              break;
            case "edit":
              btn_edit(obj.data);
              break;
            case "del":
              btn_del(obj.data);
              break;
          }
        });

        //监听单元格编辑
        treeTable.on('edit(companyTable)', function (obj) {
          var udata = {
            id: obj.data.id,
            field: 'sort',
            value: obj.value
          };
          szoa.post('/hrm.company/setsort', udata, function (res) {
            layer.tips('修改完成', obj.td);
          });
        });

        function dselhead() {
          tableSelect.render({
            elem: '#sel_headman',
            searchKey: 'keywords',
            checkedKey: 'id',
            table: {
              url: '/select/employee',
              cols: [[
                { type: 'radio' },
                { field: 'id', title: 'ID', hide: true },
                { field: 'real_name', title: '姓名' },
                { field: 'phone', title: '手机' },
                { field: 'dept_id_name', title: '部门' }
              ]]
            },
            done: function (elem, data) {
              var NEWJSON = [], ids = [];
              layui.each(data.data, function (index, item) {
                NEWJSON.push(item.real_name);
                ids.push(item.id);
              })
              elem.val(NEWJSON.join(","));
              $('input[name=headid]').val(ids.join(","));
            }
          })
        }

        function duimg() {
          //上传logo
          kaige.upload_multi_files({
            input_id: '#logo_imgid',
            img_id: '#logo_imgsrc',
            btn: '#logo_upbtn',
            url: szoa.client.path + '/pages/files/upfiles.html?id=7'
          });

          kaige.upload_multi_files({
            input_id: '#inputimgguid1',
            img_id: '#srcimgurl1',
            btn: '#editimg1',
            url: szoa.client.path + '/pages/files/upfiles.html?id=7'
          });
          kaige.upload_multi_files({
            input_id: '#inputimgguid2',
            img_id: '#srcimgurl2',
            btn: '#editimg2',
            url: szoa.client.path + '/pages/files/upfiles.html?id=7'
          });
          kaige.upload_multi_files({
            input_id: '#inputimgguid3',
            img_id: '#srcimgurl3',
            btn: '#editimg3',
            url: szoa.client.path + '/pages/files/upfiles.html?id=7'
          });
        }

        function treelist() {
          //单位选择
          kaige.xmSelectTree({
            id: 'company_id',
            url: '/select/companytree',
            udata: { automatch: 1 },
            radio: true,
            clickClose: true
          });
        }
        //添加
        function btn_add() {
          kaige.form({
            title: '<i class="layui-icon layui-icon-add-circle"></i> 添加'
            , url: '/hrm.company/add' //数据源
            , data: {}
            , id: 'kaige'
            , area: ['800px', '450px']
            , encode: 1
            , callbefore: function () {
              treelist();
              duimg();
              dselhead();
              getlatlon_hand();
            }
            , postbefore: function (udata) {
              var updata = udata;
              updata.is_lock = updata.is_lock ? 1 : 2;
              updata.is_auto_kbzj = updata.is_auto_kbzj ? 1 : 2;
              updata.type = updata.type ? 1 : 2;
              return updata;
            }
            , callback: function (res) {
              res.status && treeTable.reloadData('IDcompanyTable');
            }
          });
        };

        function btn_edit(d) {
          kaige.form({
            title: '<i class="layui-icon layui-icon-edit"></i> 编辑'
            , url: '/hrm.company/edit' //数据源
            , data: { id: d.id }
            , id: 'kaige'
            , area: ['800px', '450px']
            , encode: 1
            , callbefore: function () {
              treelist();
              duimg();
              dselhead();
              getlatlon_hand();
            }
            , postbefore: function (udata) {
              var updata = udata;
              updata.is_lock = updata.is_lock ? 1 : 2;
              updata.is_auto_kbzj = updata.is_auto_kbzj ? 1 : 2;
              updata.type = updata.type ? 1 : 2;
              return updata;
            }
            , callback: function (res) {
              res.status && treeTable.reloadData('IDcompanyTable');
            }
          });
        }

        function btn_look(d) {
          kaige.details({
            title: '<i class="layui-icon layui-icon-eye"></i> 查看'
            , url: '/hrm.company/look' //数据源
            , data: { id: d.id }
            , id: 'look'
            , area: ['85%', '83%']
            , overflow: 0
            , callbefore: function () {
              layui.element.render();
            }
          });
        }

        function btn_del(d) {
          layer.confirm('真的要删除么', { icon: 3, title: '名称：' + d.name }, function (index) {
            $.post('/hrm.company/del', { id: d.id }, function (res) {
              if (res.status) {
                layer.msg(res.msg, { time: 1000 }, function () {
                  treeTable.reloadData('IDcompanyTable');
                  layer.close(index);
                });
              } else {
                layer.msg(res.msg);
              }
            });
          });
        }

        //监听启禁用操作
        form.on('switch(status)', function (obj) {
          var udata = {
            id: (this.value).trim(),
            field: 'status',
            value: obj.elem.checked ? 1 : 2
          };
          szoa.post('/hrm.company/setdisabled', udata, function (res) {
            layer.tips(udata.value == 1 ? '启用' : '禁用', obj.othis);
          });
        });

        function getlatlon_hand() {
          $("#getpoint").on('click', function (e) {
            var url = '//lbs.qq.com/tool/getpoint/getpoint.html';
            layer.open({
              title: '坐标拾取器',
              shade: 0,
              type: 2,
              content: url,
              area: ['980px', '550px'],
              maxmin: true,
            });
          });
        }


      });
    });
  </script>
  <script type="text/html" id="kaige_form_html">
    <form class="layui-form layui-form-pane kaige-body-form" lay-filter="kaige_form_lay_filter">
      {{# if(d.id){ }}
        <input type="hidden" name="id" value="{{ d.id }}" />
      {{# } }}
      <div class="layui-tab layui-tab-brief" style="margin-top:1px;">
          <ul class="layui-tab-title">
              <li class="layui-this">
                <span class="layui-badge layui-bg-blue">1</span>&nbsp;&nbsp;&nbsp;&nbsp;基本信息
              </li>
              <li>
                <span class="layui-badge layui-bg-blue">2</span>&nbsp;&nbsp;&nbsp;&nbsp;位置信息
              </li>
              <li>
                <span class="layui-badge layui-bg-blue">3</span>&nbsp;&nbsp;&nbsp;&nbsp;档案信息
              </li>
          </ul>
          <div class="layui-tab-content">
              <div class="layui-tab-item layui-show">
                  <div class="layui-form-item">
                      <label class="layui-form-label">单位上级</label>
                      <div class="layui-input-inline" style="margin-top: 1px;min-width:220px">
                        <div id="company_id_select_box"></div>
                        <input type="hidden" id="company_id_name" value="{{ d.name || '' }}" />
                        <input type="hidden" id="company_id" value="{{ d.pid || '' }}" name="pid" />
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label">单位简称</label>
                      <div class="layui-input-inline" style="width:220px">
                          <input type="text" name="name" required lay-verify="required"  value="{{ d.name || '' }}" placeholder="请输入单位简称" autocomplete="off" class="layui-input"/>
                      </div>
                      <label class="layui-form-label">编码</label> 
                      <div class="layui-input-inline" style="width:219px">
                          <input type="text" name="code" required lay-verify="required"  value="{{ d.code || '' }}" placeholder="请输入编码" autocomplete="off" class="layui-input"/>
                      </div>        
                  </div>

                  <div class="layui-form-item">
                      <label class="layui-form-label">单位全称</label>
                      <div class="layui-input-inline" style="width:220px">
                          <input type="text" name="fullname" required lay-verify="required"  value="{{ d.fullname || '' }}" placeholder="请输入单位全称" autocomplete="off" class="layui-input"/>
                      </div>
                      <label class="layui-form-label">负责人</label>
                      <div class="layui-input-inline" style="width:220px">
                          <input type="text" name="headman" value="{{ d.headman ||'' }}" autocomplete="off" class="layui-input" id="sel_headman"/>
                          <input type="hidden" name="headid" value="{{ d.headid || ''}}"/>
                      </div>
                  </div>

                  <div class="layui-form-item">
                      <label class="layui-form-label">LOGO</label>
                      <div class='layui-input-inline' style="width: 100px;">
                          <img id="logo_imgsrc" style="height:auto;max-height:32px;min-width:32px" onclick="viewImage(this.src)" src="{{ d.logo_url || '' }}"/>
                          <input type="hidden" name="logo" id="logo_imgid" value="{{ d.logo || ''}}">
                      </div>
                      <div class='layui-input-inline' style="width: 111px;">
                          <a class="layui-btn layui-bg-blue layui-btn-sm" id="logo_upbtn">上传</a>
                      </div>
                      <label class="layui-form-label">电话</label>
                      <div class="layui-input-inline" style="width:220px">
                          <input type="tel" name="tel" value="{{ d.tel||'' }}" autocomplete="off" class="layui-input"/>
                      </div>
                  </div>

                  <div class="layui-form-item">
                      
                      <label class="layui-form-label">传真</label>
                      <div class="layui-input-inline" style="width:220px">
                          <input type="tel" name="fax" class="layui-input" value="{{ d.fax ||'' }}" />
                      </div> 
                  </div>

                  <div class="layui-form-item">
                      
                      <label class="layui-form-label">排序</label>
                      <div class="layui-input-inline" style="width:220px">
                          <input type="number" name="sort" class="layui-input" value="{{ typeof(d.sort)==='number' ? d.sort: '' }}" />
                      </div>  
                      <label class="layui-form-label">状态</label>
                      <div class="layui-input-inline border3" style="width:219px">
                          <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|禁用" {{#  if(d.status ==1 ){ }} checked {{#  } }} />
                      </div> 
                  </div>
              </div>

              <div class="layui-tab-item">
                  <div class="layui-form-item">
                      <label class="layui-form-label">地址</label>
                      <div class="layui-input-inline border3" style="width:219px">
                          <input type="text" name="address" class="layui-input" value="{{ d.address||'' }}"/>
                      </div>
                      <div class="layui-input-inline">
                          <button type="button" id="getpoint" class="layui-btn layui-bg-blue layui-btn-sm" style="margin-top:3px;margin-left: 5px;">坐标拾取器</button>
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label">国家</label>
                      <div class="layui-input-inline" style="width:220px">
                          <input type="text" name="nation" class="layui-input" value="{{ d.nation ||'' }}" />
                      </div>
                      <label class="layui-form-label">省份</label>
                      <div class="layui-input-inline" style="width:220px">
                          <input type="text" name="province" class="layui-input" value="{{ d.province || '' }}" />
                      </div>                      
                  </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label">城市</label>
                      <div class="layui-input-inline" style="width:220px">
                          <input type="text" name="city" class="layui-input" value="{{ d.city || '' }}" />
                      </div>                      
                      <label class="layui-form-label">县/市</label>
                      <div class="layui-input-inline" style="width:220px">
                          <input type="text" name="district" class="layui-input" value="{{ d.district ||'' }}" />
                      </div>
                  </div>  
                  <div class="layui-form-item">
                      <label class="layui-form-label">街/道</label>
                      <div class="layui-input-inline" style="width:220px">
                          <input type="text" name="street" class="layui-input" value="{{ d.street|| '' }}" />
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label">纬度</label>
                      <div class="layui-input-inline" style="width:220px">
                          <input type="text" name="lat" class="layui-input" value="{{ d.lat|| '' }}" />
                      </div>                      
                      <label class="layui-form-label">经度</label>
                      <div class="layui-input-inline" style="width:220px">
                          <input type="text" name="lon" class="layui-input" value="{{ d.lon|| '' }}" />
                      </div>                      
                  </div>

              </div>
              <div class="layui-tab-item">
                  <div class="layui-form-item">
                      <label class="layui-form-label">法人姓名</label>
                      <div class="layui-input-inline" style="width:220px">
                          <input type="text" name="bl_sfz_name" class="layui-input" value="{{ d.bl_sfz_name || '' }}" />
                      </div>
                      <label class="layui-form-label">法人手机号</label>
                      <div class="layui-input-inline" style="width:220px">
                          <input type="tel" name="bl_phone" value="{{ d.bl_phone || '' }}" autocomplete="off" class="layui-input" />
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label">法人身份证</label>
                      <div class="layui-input-inline" style="width:220px">
                          <input type="text" name="bl_sfz_code" class="layui-input" value="{{ d.bl_sfz_code || '' }}" />
                      </div>
                      <label class="layui-form-label">身份证图</label>
                      <div class='layui-inline'>
                          <img id="srcimgurl2" style="height:auto;max-height:32px;min-width:32px" onclick="viewImage(this.src)" src="{{ d.bl_sfz_img_url || '' }}"/>
                          <input type="hidden" name="bl_sfz_img" id="inputimgguid2" value="{{ d.bl_sfz_img || '' }}">
                      </div>
                      <div class='layui-inline'>
                          <a class="layui-btn layui-bg-blue layui-btn-sm" id="editimg2">上传图片</a>
                      </div>
                  </div>
                  
                  <div class="layui-form-item">
                      <label class="layui-form-label">营业执照代码</label>
                      <div class="layui-input-inline" style="width:220px">
                          <input type="text" name="bl_code" class="layui-input" value="{{ d.bl_code|| '' }}" />
                      </div>  
                      <label class="layui-form-label">营业执照图</label>
                      <div class='layui-inline'>
                          <img id="srcimgurl1" style="height:auto;max-height:32px;min-width:32px" onclick="viewImage(this.src)" src="{{ d.bl_img_url || '' }}"/>
                          <input type="hidden" name="bl_img" id="inputimgguid1" value="{{ d.bl_img|| '' }}">
                      </div>
                      <div class='layui-inline'>            
                          <a class="layui-btn layui-bg-blue layui-btn-sm" id="editimg1">上传图片</a>
                      </div>
                  </div>

              </div>
          </div>
      </div>
      <div class="layui-form-item layui-hide">
        <button class="layui-hide" lay-submit="" id="kaige_form_btn_save" lay-filter="kaige_form_btn_save">保存数据</button>
      </div>
  </form>
  </script>
  <script type="text/html" id="status_td">
    <input type="checkbox" value="{{ d.id }}" data-id="{{ d.id }}" lay-skin="switch" lay-text="启用|禁用" lay-filter="status" {{ (d.status == 1) ? "checked" : "" }}/>
  </script>

  <script type="text/html" id="look_form_html">
    <div class="layui-collapse">
      <div class="layui-colla-item">
        <div class="layui-colla-title">基本信息</div>
        <div class="layui-colla-content layui-show">
          <div class="layui-form-item">
            <table class="layui-table">
              <tr>
                <td style="width: 15%;">单位上级</td>
                <td>{{ d.company_id_name || "无" }}</td>
              </tr>
              <tr>
                <td>LOGO</td>
                <td><img style="max-height:100px;min-width:100px" src="{{ d.logo_url || '' }}" onclick="viewImage(this.src)"/></td>
              </tr>
              <tr>
                <td>单位简称</td>
                <td>{{ d.name }}</td>
              </tr>
              <tr>
                <td>单位全称</td>
                <td>{{ d.fullname }}</td>
              </tr>
              <tr>
                <td>单位编码</td>
                <td>{{ d.code }}</td>
              </tr>
              <tr>
                <td>负责人</td>
                <td>{{ d.headman }}</td>
              </tr>
              <tr>
                <td>电话</td>
                <td>{{ d.tel }}</td>
              </tr>
              <tr>
                <td>传真</td>
                <td>{{ d.fax }}</td>
              </tr>
              <tr>
                <td>状态</td>
                <td>{{ d.status ==1 ? "启用":"禁用" }}</td>
              </tr>
            </table>
        </div>
        </div>
      </div>
      <div class="layui-colla-item">
        <div class="layui-colla-title">位置信息</div>
        <div class="layui-colla-content layui-show">
          <table class="layui-table">
            <tr>
              <td>纬度</td>
              <td>{{ d.lat }}</td>
              <td>经度</td>
              <td>{{ d.lon }}</td>
            </tr>
            <tr>
              <td style="width: 15%;">国家</td>
              <td style="width: 35%;">{{ d.nation }}</td>
              <td style="width: 15%;">省份</td>
              <td>{{ d.province }}</td>
            </tr>
            <tr>
              <td>城市</td>
              <td>{{ d.city }}</td>
              <td>县/市</td>
              <td>{{ d.district }}</td>
            </tr>
            <tr>
              <td>街/道</td>
              <td colspan="3">{{ d.street }}</td>
            </tr>            
            <tr>
              <td>地址</td>
              <td colspan="3">{{ d.address }}</td>
            </tr>
          </table>
        </div>
      </div>
      <div class="layui-colla-item">
        <div class="layui-colla-title">档案信息</div>
        <div class="layui-colla-content">
          <table class="layui-table">
            <tr>
              <td style="width: 15%;">法人姓名</td>
              <td style="width: 35%;">{{ d.bl_sfz_name }}</td>
              <td style="width: 15%;">法人手机号</td>
              <td>{{ d.bl_phone }}</td>
            </tr>
            <tr>
              <td>法人身份证</td>
              <td colspan="3">{{ d.bl_sfz_code }}</td>
            </tr>
            <tr>
              <td>身份证图</td>
              <td colspan="3"><img style="height:auto;max-height:240px;min-width:500px" src="{{ d.bl_sfz_img_url || '' }}" onclick="viewImage(this.src)"/></td>
            </tr>
            <tr>
              <td>营业执照代码</td>
              <td colspan="3">{{ d.bl_code }}</td>
            </tr>
            <tr>
              <td>营业执照图</td>
              <td colspan="3"><img style="height:auto;max-height:1200px;min-width:800px" src="{{ d.bl_img_url || '' }}" onclick="viewImage(this.src)"/></td>
            </tr>
          </table>
        </div>
      </div>
    </div>
  </script>
</body>

</html>